#include "dlgsetbase.h"
#include "unistd.h"

DlgSetBase::DlgSetBase(QWidget *parent) : QWidget(parent)
{
    this->setGeometry(QRect(300, 100, 600, 300));

    this->setMinimumSize(600,300);
    this->setMaximumSize(600,300);
    this->setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏


    label_pic_bg = new QLabel(this);
   // label_pic_bg->setGeometry(QRect(300, 150, 600, 400));
    label_pic_bg->setPixmap(QPixmap(":/images/set_bg.png"));
    label_pic_bg->setScaledContents(true);

    //显示按钮
    ok = new Button(this);
    ok->setButtonPicture(QPixmap( ":/images/ok_1.png"));
    ok->setPressPicture(QPixmap( ":/images/ok_2.png"));
    ok->setReleasePicture(QPixmap( ":/images/ok_1.png"));
    ok->setEnterPicture(QPixmap( ":/images/ok_2.png"));
    ok->setReleasePicture(QPixmap( ":/images/ok_1.png"));
    ok->set_X_Y_width_height(150,230,120,60);
    connect(ok,SIGNAL(clicked()),this,SLOT(goSet()) );


    cancel = new Button(this);
    cancel->setButtonPicture(QPixmap( ":/images/cancel_1.png"));
    cancel->setPressPicture(QPixmap( ":/images/cancel_2.png"));
    cancel->setReleasePicture(QPixmap( ":/images/cancel_1.png"));
    cancel->setEnterPicture(QPixmap( ":/images/cancel_2.png"));
    cancel->setReleasePicture(QPixmap( ":/images/cancel_1.png"));
    cancel->set_X_Y_width_height(330,230,120,60);
    connect(cancel,SIGNAL(clicked()),this,SLOT(close()) );

    keyNum = new KeyNum(this);
    keyNum->setItem("网络更新间隔(小时):");
    keyNum->setGeometry(50,30,500,200);

    isOK = false;
}

void DlgSetBase::setItem(ShowLabel *item)
{
   inputItem = item;
}


void DlgSetBase::goSet()
{
    int timer = keyNum->getValue().toInt();
    if(timer>0 && timer < 13)
    {
       // keyNum->showRet(tr("设置成功!"));
        qDebug() << keyNum->getValue();
        inputItem->setText( keyNum->getValue() + " 小时");
        close();
    }else{
        keyNum->showRet(tr("设置无效!"));
    }

}
